package com.moyun.syssecurity.config;

import org.springframework.security.web.session.InvalidSessionStrategy;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * <h3>moyun-base</h3>
 * <p>会话过期的策略类</p>
 *
 * @author : ybx
 * @date : 2021-08-30 10:11:50
 **/
public class MyInvalidSessionStrategy implements InvalidSessionStrategy {
    @Override
    public void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        // 返回异常信息
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.print("{\"code\":\"1\",\"msg\":\" 您的会话已经失效(session失效),请重新登录\"}");
        out.flush();
        out.close();
    }
}
